/**
 * @author LKQ
 * @date 2022/2/23 11:54
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        ListNode t2 = new ListNode(2, new ListNode(4));
        ListNode headA = new ListNode(0, new ListNode(9, new ListNode(1, t2)));
        ListNode headB = new ListNode(3, t2);
        solution.getIntersectionNode(headA, headB);
    }
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) {
            return null;
        }
        ListNode p1 = headA, p2 = headB;
        while (p1 != p2) {
            p1 = p1 == null ? headB: p1.next;
            p2 = p2 == null ? headA: p2.next;
        }
        return p1;
    }
}
